<script>
import config from '@/common/config'
import tabBar from "@/utils/tabbar"
export default {
  onLaunch: function () {
   try {
             var res = wx.getSystemInfoSync();
             config.pixelRate = res.windowWidth / 750;
             config.platform = res.platform;
             config.statusBarHeight = res.statusBarHeight;
             if(res.platform.toLowerCase() == 'devtools'){
                 config.capsuleHeight = 44;
             }
             if(res.platform.toLowerCase() == 'android'){
                 config.capsuleHeight = 48;
             }
             config.titleHeight = (config.capsuleHeight + config.statusBarHeight) / config.pixelRate ;
             if(res.statusBarHeight >= 44){
                 config.isHighHead = true;
             }
             if (res.windowHeight > 750) config.isAllScreen = true;
             config.systemHeight = res.windowHeight;
         } catch (e) {
             console.log(e);
         }
      //隐藏官方的tabBar
      uni.hideTabBar()
      // 初始化 tabBar 配置
      uni.setStorageSync('tabBarRole', 0);//默认代表未切换角色
      uni.setStorageSync('tabBarList', tabBar[0])
      // 设置默认选中的 tabBar
      uni.setStorageSync('tabBarSelected', 0)
      
      // 注册自定义 tabBar 组件
      uni.$u.setConfig({
        config: {
          tabBar: {
            list: tabBar[0]
          }
        }
      })
      
		 const updateManager = wx.getUpdateManager();
		 const startParamObj = wx.getEnterOptionsSync();
		 if (wx.canIUse('getUpdateManager') && startParamObj.scene != 1154) {
		 	const updateManager = wx.getUpdateManager()
		 	updateManager.onCheckForUpdate(function(res) {
		 		// 请求完新版本信息的回调
		 		  
		 		if (res.hasUpdate) {
		 			updateManager.onUpdateFailed(function() {
		 				return that.Tips({
		 					title: '新版本下载失败'
		 				});
		 			});
		 			updateManager.onUpdateReady(function() {
		 				wx.showModal({
		 					title: '更新提示',
		 					content: '新版本已经下载好，是否重启当前应用？',
		 					success(res) {
		 						if (res.confirm) {
		 							updateManager.applyUpdate()
		 						}
		 					}
		 				})
		 			})
		 			updateManager.onUpdateFailed(function() {
		 				wx.showModal({
		 					title: '发现新版本',
		 					content: '请删除当前小程序，重启搜索打开...',
		 				})
		 			})
		 		}
		 	})
		 }
  },
  onShow: function () {
   try {
             var res = wx.getSystemInfoSync();
             config.pixelRate = res.windowWidth / 750;
             config.platform = res.platform;
             config.statusBarHeight = res.statusBarHeight;
             if(res.platform.toLowerCase() == 'devtools'){
                 config.capsuleHeight = 44;
             }
             if(res.platform.toLowerCase() == 'android'){
                 config.capsuleHeight = 48;
             }
             config.titleHeight = (config.capsuleHeight + config.statusBarHeight) / config.pixelRate ;
             if(res.statusBarHeight >= 44){
                 config.isHighHead = true;
             }
             if (res.windowHeight > 750) config.isAllScreen = true;
             config.systemHeight = res.windowHeight;
         } catch (e) {
             console.log(e);
         }
  },
  onHide: function () {
    console.log('App Hide')
  },
}
</script>

<style lang="scss">
/** 引入全局基本样式 */
@import 'styles/base.scss';
@import 'global/public.css';
/* 引入 uView 基础样式 */
@import '@/uni_modules/uview-ui/index.scss';

/*每个页面公共scss */
@import 'app.scss';
</style>
